﻿using DZParallelLib.DZImage;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Drawing;
using System.Linq;

namespace DZParallelLib.Test.DZImage
{
    [TestClass]
    public class DZImageLevelDescriptorTest
    {
        [TestMethod]
        public void TestLevel9()
        {
            var imageDescriptor = new DZImageLevelDescriptor(
                new Size(256 + 92, 236), 256, 1);

            Assert.IsNotNull(imageDescriptor, "Main return");
            Assert.IsNotNull(imageDescriptor.Images, "Images");
            var tiles = imageDescriptor.Images.ToArray();
            Assert.AreEqual(2, tiles.Length, "# of images");
            Assert.AreEqual((ulong)0, tiles[0].X, "image 0, x0");
            Assert.AreEqual((ulong)0, tiles[0].Y, "image 0, y0");
            Assert.AreEqual((uint)257, tiles[0].Width, "image 0, width");
            Assert.AreEqual((uint)236, tiles[0].Height, "image 0, height");
            Assert.AreEqual("0_0.png", tiles[0].Name, "image 0, Name");
            Assert.AreEqual((ulong)256, tiles[1].X, "image 1, x0");
            Assert.AreEqual((ulong)0, tiles[1].Y, "image 1, y0");
            Assert.AreEqual((uint)93, tiles[1].Width, "image 1, width");
            Assert.AreEqual((uint)236, tiles[1].Height, "image 1, height");
            Assert.AreEqual("1_0.png", tiles[1].Name, "image 1, Name");
        }

        [TestMethod]
        public void TestLevel0()
        {
            var imageDescriptor = new DZImageLevelDescriptor(
                new Size(1, 1), 256, 1);

            var tiles = imageDescriptor.Images.ToArray();
            Assert.AreEqual(1, tiles.Length, "# of tiles");
            Assert.AreEqual((uint)1, tiles[0].Width, "width");
            Assert.AreEqual((uint)1, tiles[0].Height, "Height");
        }

        [TestMethod]
        public void TestLevel10()
        {
            var imageDescriptor = new DZImageLevelDescriptor(
                new Size(696, 472), 256, 1);

            var tiles = imageDescriptor.Images.ToArray();
            Assert.AreEqual(6, tiles.Length, "# of tiles");
            Assert.AreEqual("2_1.png", tiles[5].Name, "Name of 6th tile");
            Assert.AreEqual((uint)185, tiles[5].Width, "Width of 6th tile");
            Assert.AreEqual((uint)217, tiles[5].Height, "Height of 6th tile");
            Assert.AreEqual((ulong)256 * 2, tiles[5].X, "X of 6th tile");
            Assert.AreEqual((ulong)256, tiles[5].Y, "Y of 6th tile");
        }
    }
}
